package com.jinjie.exception;

/**
 * @program: com.jinjie.exception
 * @Description:
 * @author: Administrator
 * @create: 2024-02-04 16:19
 **/
public class CommonRuntimeException extends RuntimeException {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * 异常类型
     */
    private Integer code;

    /**
     * 异常消息
     */
    private String message;


    public CommonRuntimeException(Integer code) {
        super();
        this.code = code;
        this.message = CommonExceptionEnum.getLabelByCode(code);

    }

    public CommonRuntimeException(CommonExceptionEnum exceptionEnum) {
        super();
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getLabel();
    }

    public CommonRuntimeException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public CommonRuntimeException(String message) {
        super();
        this.message = message;
    }


    /**
     * 重写 fillInStackTrace 去除业务异常堆栈信息，提高性能
     * 业务逻辑异常是可预料异常范围，不需要堆栈信息，堆栈信息会大大提高系统开销，影响系统性能
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return this.message;
    }

}
